package com.neutech.solar.util;


import com.neutech.solar.constant.Constant;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * 图片工具类
 * 使用 I/O流 加载图片
 * I：InputStream   输入流
 * O：OutputStream  输出流
 */
public class ImageUtil {

    public static Map<String,Image> maps = new HashMap<>();
    static {
        maps.put("bg",ImageUtil.getImage("bg.png"));
        maps.put("Sun",ImageUtil.getImage("00.Sun.png"));
        maps.put("Mercury",ImageUtil.getImage("01.Mercury.png"));
        maps.put("Venus",ImageUtil.getImage("02.Venus.png"));
        maps.put("Earth",ImageUtil.getImage("03.Earth.png"));
        maps.put("Mars",ImageUtil.getImage("04.Mars.png"));
        maps.put("Jupiter",ImageUtil.getImage("05.Jupiter.png"));
        maps.put("Saturn",ImageUtil.getImage("06.Saturn.png"));
        maps.put("Uranus",ImageUtil.getImage("07.Uranus.png"));
        maps.put("Neptune",ImageUtil.getImage("08.Neptune.png"));

        maps.put("smallPlanet",ImageUtil.getImage("09.Pluto.png"));
    }

    // 构造方法私有
    private ImageUtil(){}


    public static Image getImage(String imageName){ // 图片路径
        URL u = ImageUtil.class.getClassLoader().getResource(Constant.IMAGE_PATH_PRE + imageName);

        BufferedImage img = null;
        try{
            img = ImageIO.read(u);
        }catch (Exception e) {
            //在控制台打印错误信息
            e.printStackTrace();
        }

        return img;
    }
}
